import { defineStore } from 'pinia';

const systemInfo = uni.getSystemInfoSync();

export const useSystemStore = defineStore('system', {
	state: () => {
		return {
			systemInfo,
			capsuleInfoLeft: '750rpx',
			navbarInfo: {
				total: 45,
				statusBar: 0,
				navigationBar: 45
			},
		};
	},

	actions: {
		async init() {
			this.initNavbarInfo();
			this.initCapsuleInfoLeft();
		},
		async initNavbarInfo() {
			// 状态栏高度
			const statusBar = systemInfo.statusBarHeight;

			//导航栏高度
			let navigationBar = systemInfo['platform'] === 'android' ? 50 : 45;

			// 标题栏高度(支付宝)
			systemInfo['titleBarHeight'] && (navigationBar = systemInfo['titleBarHeight'])

			// 导航栏的高度（百度小程序）
			systemInfo['navigationBarHeight'] && (navigationBar = systemInfo['navigationBarHeight'])

			this.navbarInfo = {
				statusBar: statusBar,
				navigationBar: navigationBar,
				total: statusBar + navigationBar
			};
		},
		async initCapsuleInfoLeft() {
			// 胶囊
			let capsuleInfoLeft = '750rpx';

			// #ifdef MP
			const { left } = uni.getMenuButtonBoundingClientRect();
			capsuleInfoLeft = left + 'px';

			// 百度小程序web化
			if (systemInfo['platform'] == "web" && systemInfo['uniPlatform'] === "mp-baidu") {
				capsuleInfoLeft = '750rpx';
			}
			// #endif

			this.capsuleInfoLeft = capsuleInfoLeft;
		}
	}
});